﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SQLAnalyticLibrary;

namespace QueryResource.Analytic
{
    internal class ColumnTableAnalytic
    {
        public void Analytic(string text)
        {
            OQLLexer lex = new OQLLexer(new CaseInsensitiveStringStream(this.textBox1.Text));
            CommonTokenStream tokens = new CommonTokenStream(lex);
            OQLParser parser = new OQLParser(tokens);
            parser.TreeAdaptor = new TreeFactory();
            OQLParser.start_return statements = null;
            statements = parser.start();
            if (statements == null || statements.tree == null)
            {
                return;
            }

            this.treeView1.Nodes.Clear();

            for (int i = 0; i < statements.tree.ChildCount; i++)
            {
                TreeNode node = new TreeNode();
                this.ShowAST(node, statements.tree.GetChild(i));
                //Expression ex = statements.tree;
                //try
                //{
                //    QueryStatement query = new QueryStatement(ex.GetChild(i).Token);
                //    statements.tree.VisitCompile(query);
                //}
                //catch { }
                this.treeView1.Nodes.Add(node);
            }

            if (statements.Tree == null) return;
        }
    }
}
